home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRSPAN.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  1KB  |  81 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; strspan-    Returns the number of characters (from a set) which
  10. ;        precede a string.
  11. ;
  12. ; inputs:
  13. ;
  14. ;    ES:DI-  Points at string to test.
  15. ;    DX:SI-    Points at set of characters (zero terminated string).
  16. ;
  17. ; outputs:
  18. ;
  19. ;    CX-    Number of characters in set which are the prefix of
  20. ;        the test string.
  21. ;
  22. ;
  23. ;
  24. ;
  25.         public    sl_strspan
  26. ;
  27. sl_strspan    proc    far
  28.         pushf
  29.         push    es
  30.         push    ds
  31.         push    ax
  32.         push    bx
  33.         push    dx
  34.         push    si
  35.         push    di
  36.         cld
  37. ;
  38.         xchg    di, si
  39.         mov    ax, es
  40.         mov    es, dx
  41.         mov    ds, ax
  42. ;
  43.         mov    bx, di            ;Preserve ptr to char set.
  44.         mov    cx, 0ffffh
  45.         mov    al, 0
  46.     repne    scasb                ;Compute length of char set.
  47.         neg    cx
  48.         dec    cx
  49.         dec    cx
  50.         mov    dx, cx            ;Save for use later.
  51. ;
  52. ; Okay, now we can see how many characters from the set match the prefix
  53. ; characters in the string.
  54. ;
  55. StrLp:        lodsb                ;Get next char in string.
  56.         mov    cx, dx            ;Get length of char set.
  57.         mov    di, bx            ;Get ptr to char set
  58.     repne    scasb                ;See if in set
  59.         jz    StrLp            ;Repeat while in set.
  60. ;
  61.         pop    cx
  62.         mov    di, cx
  63.         sub    cx, si
  64.         neg    cx
  65.         dec    cx
  66.         pop    si
  67.         pop    dx
  68.         pop    bx
  69.         pop    ax
  70.         pop    ds
  71.         pop    es
  72.         popf
  73.         ret
  74. sl_strspan    endp
  75. ;
  76. ;
  77. ;
  78. ;
  79. stdlib        ends
  80.         end
  81.